home *** CD-ROM | disk | FTP | other *** search
- head 1.4;
- branch ;
- access ;
- symbols beta10:1.3;
- locks death:1.4;
- comment @@;
-
-
- 1.4
- date 93.04.04.23.44.52; author death; state Exp;
- branches ;
- next 1.3;
-
- 1.3
- date 93.01.10.15.08.35; author death; state Exp;
- branches ;
- next 1.2;
-
- 1.2
- date 92.07.26.13.59.51; author death; state Exp;
- branches ;
- next 1.1;
-
- 1.1
- date 92.07.26.13.54.11; author death; state Exp;
- branches ;
- next ;
-
-
- desc
- @Basic ps file
- @
-
-
- 1.4
- log
- @Sun Apr 4 23:44:52 PDT 1993
- @
- text
- @#import "PSFile.h"
- #import<stdio.h>
- #import <stdlib.h>
- #import <string.h>
- #include <stdarg.h> // For variable arguments stuff
-
- @@implementation PSFile
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Method: writeDCDcomment:
- // Parameters: the line of text we are to write as a comment
- // Returns: a Reply
- // Description:
- // This writes the specified string to the PS file, following it with a newline, and
- // preceeding it immediately with a %% so it appears as a PS DCD comment
- // It does no formatting of the line, as some other smarter routine should.
- // Note:
- // This blindly assumes that it first thing on a new line. A good PS file object
- // should be keeping track of these things, and jump to a new line if we aren't.
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- - WriteDSCComment: (CString) comment
- {
- CString output = NewCString(strlen(comment) + 4);
-
- sprintf(output, "%%%%%s\n", comment); //That's, two percents and a string. =)
- [self Write: strlen(output) BytesFrom: (ByteString) output];
- FreeCString(output);
- return self;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Method: WriteDSCCommentUsing:WithFormat:
- // Parameters: A buffer provided by the caller, a format, and N arguments to be written
- // Returns: self
- // Stores: nothing (bug)
- // Description:
- // This writes out a text string given variable arguments, as a DSC comment.
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- - WriteDSCCommentUsing: (CString) buffer WithFormat: (CString) format, ...;
- {
- va_list parameter_list;
- CString output;
-
- va_start(parameter_list, format);
-
- vsprintf(buffer, format, parameter_list); // doc implies this does a va_end
-
- output = NewCString(strlen(buffer) + 4);
- sprintf(output, "%%%%%s\n", buffer); //That's, two percents and a string. =)
- [self Write: strlen(output) BytesFrom: (ByteString) output];
- FreeCString(output);
- return self;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Method: WriteComment:
- // Parameters: the line of text we are to write as a comment
- // Returns: a Reply
- // Description:
- // This writes the specified string to the PS file, following it with a newline, and
- // preceeding it immediately with a %.
- // It does no formatting of the line, as some other smarter routine should.
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- - WriteComment: (CString) comment
- {
- CString output = NewCString(strlen(comment) + 3);
-
- sprintf(output, "%%%s\n", comment); //That's, one percent and a string. =)
- [self Write: strlen(output) BytesFrom: (ByteString) output];
- FreeCString(output);
- return self;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Method: WriteCommentUsing:WithFormat:
- // Parameters: A buffer provided by the caller, a format, and N arguments to be written
- // Returns: self
- // Stores: nothing (bug)
- // Description:
- // This writes out a text string given variable arguments, as a PS comment.
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- - WriteCommentUsing: (CString) buffer WithFormat: (CString) format, ...;
- {
- va_list parameter_list;
- CString output;
-
- va_start(parameter_list, format);
-
- vsprintf(buffer, format, parameter_list); // doc implies this does a va_end
-
- output = NewCString(strlen(buffer) + 2);
- sprintf(output, "%%%s\n", buffer); //That's, 1 percent and a string.
- [self Write: strlen(output) BytesFrom: (ByteString) output];
- FreeCString(output);
- return self;
- }
-
-
-
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Method: writePSline:
- // Parameters: the line of text we are to write
- // Returns: a Reply
- // Description:
- // This writes the specified string to the PS file, following it with a newline.
- // It does no formatting of the line, as some other smarter routine should.
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- - WritePSLine: (CString) theLine
- {
- CString output = NewCString(strlen(theLine) + 2);
-
- sprintf(output, "%s\n", theLine);
- [self Write: strlen(output) BytesFrom: (ByteString) output];
- FreeCString(output);
- return self;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Method: WritePSLineUsing:WithFormat:
- // Parameters: A buffer provided by the caller, a format, and N arguments to be written
- // Returns: self
- // Stores: nothing (bug)
- // Description:
- // This writes out a text string given variable arguments
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- - WritePSLineUsing: (CString) buffer WithFormat: (CString) format, ...;
- {
- va_list parameter_list;
- CString output;
-
- va_start(parameter_list, format);
-
- vsprintf(buffer, format, parameter_list); // doc implies this does a va_end
-
- output = NewCString(strlen(buffer) + 1);
- sprintf(output, "%s\n", buffer);
- [self Write: strlen(output) BytesFrom: (ByteString) output];
- FreeCString(output);
- return self;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Method: write:BytesOfHexData:
- // Parameters: The number of Bytes to write
- // A buffer of binary data
- // Returns: self
- // Description:
- // This method writes out num Bytes of data from the buffer specified by buffer.
- // buffer is not modified. Each Byte is converted to a pair of hexidcecimal digits,
- // and these are written out. When the whole buffer has been written, a newline
- // is added.
- // The intended use for this method is for dumping raw image data to be used
- // with PS operators like (surprisingly) image.
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- - Write: (PositiveInteger) num BytesOfHexDataFrom: (ByteString) buffer
- {
- PositiveInteger index;
- for (index = 0; index < num; index++)
- [self WriteByteAsHex: buffer[index]];
- [self ForceNewLine];
- return self;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Method: write:InvertedBytesOfHexDataFrom:
- // Parameters: The number of Bytes to write
- // A buffer of binary data
- // Returns: self
- // Description:
- // This method writes out num Bytes of data from the buffer specified by buffer.
- // buffer is not modified. Each Byte is converted to a pair of hexidcecimal digits,
- // and these are written out with a newline following all.
- // During the process, the Byte is inverted (thus 00 becomes FF, etc.
- // The intended use for this method is for dumping raw image data to be used
- // with PS operators like (surprisingly) image.
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- - Write: (PositiveInteger) num InvertedBytesOfHexDataFrom: (ByteString) buffer
- {
- PositiveInteger index;
- for (index = 0; index < num; index++)
- [self WriteByteAsHex: ~buffer[index]];
- [self ForceNewLine];
- return self;
- }
-
-
- - ForceNewLine
- {
- return [self WriteByte: (Byte) '\n'];
- return self;
- }
-
-
- - WriteByteAsHex: (Byte) theByte
- {
- Byte nibble1 = theByte >> 4;
- Byte nibble2 = (theByte & 0x0F);
-
- if (nibble1 < 10)
- [self WriteByte: (Byte) '0'+nibble1]; // digit 0-9
- else
- [self WriteByte: (Byte) 'A'+nibble1-10]; // cap A-F
-
- if (nibble2 < 10)
- [self WriteByte: (Byte) '0'+nibble2]; // digit 0-9
- else
- [self WriteByte: (Byte) 'A'+nibble2-10]; // cap A-F
- return self;
- }
-
-
- @@end@
-
-
- 1.3
- log
- @Sun Jan 10 15:08:35 PST 1993
- @
- text
- @@
-
-
- 1.2
- log
- @updated psfile
- @
- text
- @a8 15
-
- - AppendFrom: sourceFile
- {
- Integer size;
- ByteString buffer;
-
- size = [sourceFile FileSize];
- buffer = NewByteString(size);
-
- [sourceFile Read: size BytesInto: buffer];
- [self Write: size BytesFrom: buffer];
- FreeByteString(buffer);
- return self;
- }
-
- d156 2
- a157 1
- // and these are written out in groups of 72 characters, followed by a newline.
- d163 1
- a163 1
- PositiveInteger index, linecnt=0;
- a164 2
- {
- linecnt++;
- d166 1
- a166 8
- if (linecnt == 36)
- {
- linecnt = 0;
- [self ForceNewLine];
- }
- }
- if (linecnt != 0)
- [self ForceNewLine];
- d179 2
- a180 2
- // and these are written out in groups of 72 characters, followed by a newline.
- // During the process, the Byte is inverted (thus 0 becomes F, etc.
- d186 1
- a186 1
- PositiveInteger index, linecnt=0;
- a187 2
- {
- linecnt++;
- d189 1
- a189 8
- if (linecnt == 36)
- {
- linecnt = 0;
- [self ForceNewLine];
- }
- }
- if (linecnt != 0)
- [self ForceNewLine];
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @@
-